//时间的
var calendarDateFormat = myApp.calendar({
    input: '#_arrivaltime_',
    monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
    input: '#receiptarrivalTime',
     monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
 });
 var calendarDateFormat = myApp.calendar({
    input: '#paybackarrivalTime',
     monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
 });
 var calendarDateFormat = myApp.calendar({
    input: '#carrivalTime',
     monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
 });
 var calendarDateFormat = myApp.calendar({
    input: '#cusdarrivalTime',
     monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
 });
  var calendarDateFormat = myApp.calendar({
    input: '#_deliveryTime',
     monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
 });
 var calendarDateFormat = myApp.calendar({
    input: '#_accountTime',
     monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
 });

 //买入时间
var calendarDateFormat = myApp.calendar({
    input: '#back_PurchaseTime',
    monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});

//到货时间
var calendarDateFormat = myApp.calendar({
    input: '#back_ArrivalTime',
    monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
 
$(function(){
	//LoadOrderStatusNumber();
	//批量优惠、改价
	  $("#Discount_box").hide();
    $("#ConfirmPrice_box").hide();

    //修改售价
//  $("#product_table").on("click", ".modify", function () {
//      myApp.popup(".ReviseAnOrder_box");
//  });
	//申请充值
    $("#stock_body").on("click",".ApplyFlow_Js",function(){
    	var id=$(this).attr("data-id");
    	ApplyFlow_Js(id);
    });
    $("#stock_body").on("click",".ApplyUSDFlow_Js",function(){
    	var id=$(this).attr("data-id");
    	ApplyUSDFlow_Js(id);
    });
    //批量修改所在地
    $("#edit_place_btn").on("click",function(){
    	myApp.popup(".ModPlace_box");
    	//所在地
		var html_Place = '<option value="">' + _("所在地") + '</option>';
		for(var i = 0; i < stock[0].Place.length; i++) {
			html_Place += '<option value="' + stock[0].Place[i][0] + '">' + _(stock[0].Place[i][1]) + '</option>';
		}
		$("#_batchplace").html(html_Place);
    });

    //批量修改货品状态
    $("#edit_status_btn").on("click",function(){
        myApp.popup(".ModStatus_box");
    });



    //批量修改原供应商
    $("#edit_PurchaseSupplier_btn").on("click",function(){
    	myApp.popup(".ModPurchaseSupplier_box");
    });
    //批量修改买价
    $("#edit_PurchasePrice_btn").on("click",function(){
    	myApp.popup(".ModPurchasePrice_box");
    });
    //批量修改销汇
    $("#edit_SalesExchangerate_btn").on("click",function(){
        myApp.popup(".SalesExchangerate_box");
    });

	//批量修改采购汇率
    $("#edit_PurchaseExchangerate_btn").on("click",function(){
    	myApp.popup(".ModPurchaseExchangerate_box");
    });

    //付款 充值金额大于0的
    $("#_chargingAmount").on("input",calMoney);

    //采购订单
    $("#product_table").on("click", ".purchase_modify", function () {
    	currentPurShow();//币种设置
        $(this).css("background-position", "-28px -103px");
		var orderId=$(this).attr("value");
        //订单信息
        $.ajax({
            url: "/Team/GetOrderInfo",//提交地址
            type: "POST",//提交方式
            data: "{'OrderID':'" + orderId + "'}",
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                var _result = eval('(' + result + ')');//eval()解析单个json对象
                if(_result.msgcode==true){
	                _result = _result.msginfo;
	                myApp.popup(".modify_pop_box");

                //基本信息
                $("#_orderID").val(_result.OrderID);
                $("#_orderStat").val(_result.OrderStatus);//隐藏域11-3                    
                $("#_shape").val(_result.Shape);
                //4C
                $("#_weight").val(_result.Weight);

                if(_result.IsFancy == 0){
                    $("#e_color").val(_result.Color);
                    $("#e_fancycolor").val("");
                }else{
                    $("#e_fancycolor").val(_result.Color);
                    $("#e_color").val("FY");
                }

                $("#e_clarity").val(_result.Clarity);

                $("#_cut").val(_result.Cut);
                $("#_polish").val(_result.Polish);
                $("#_symmetry").val(_result.Symmetry);
                $("#_fluorescence").val(_result.Fluorescence);
                $("#_certType").val(_result.CertType);
                $("#_certno").val(_result.CertNo);  

                //采购部分
                $("#_supplierCodeValue").val(_result.SupplierCode);

                $("#_discountReturn").val(_result.DiscountReturn);
                $("#_priceUSD").val(_result.PriceUSD);

                $("#_rapnet").val(_result.Rapnet);
                $("#_isFancy").val(_result.IsFancy);

                $("#_originSN").val(_result.OriginSN);
                $("#_deliveryTime").val(DateTimeFormat(_result.DeliveryTime));
                $("#_purchasesRemarks").val(_result.PurchaseRemarks);

                $("#_purchaseExchange").val(_result.PurchaseExchangerate);//01-10
                $("#_purchaseRMB").val(_result.PurchaseRMB);//01-10                     
				}else{
	                $(".modify_pop_box").hide();
	                toast(_(_result.msginfo));
	            }
            }
        });
        
    });

    //点击付款事件
    $("#ReceiptOrders").click(function () {
        pstalist = {};
        for (var i = 0; i < $("#stock_body .check_list_box span.selected").length ; i++) {//得到所有选中的行
//          var _skey = $("#stock_body .check_list_box span.selected").rq.attr("lang");//得到当前选中的行CustomerID
            var pays = $("#stock_body .check_list_box span.selected").eq(i).parent().attr("data-receiptstatus");//得到付款状态值
            pstalist[pays] = pays;//支付数组
        }
        var total_price = $(".check_first").html();
        var pleng = 0;//主要用来做首行判断
        var psta = true;//是否是未收状态
        for (var pp in pstalist) {
            //if (pstalist[pp] != 0) {//当前用户与首次不同
            if (pstalist[pp] == 1) {//当前用户与首次不同  1已付 0未收和2未清可以付款
                psta = false;
                break;
            }
            pleng++;
        }

        if (psta) {
            //通过
            ReceiptOrders_Js();//付款
        } else {
            myApp.alert(_("【付款】选择不当！请选择'未付''未清'订单"));
        }        
    });
	//点击修改备注
	$("#RemarkOrder_btn").on("click",function(){
		RemarkOrder();
	});

});

 
//选采购
function ModifyPurchaseUserID_Js() {
	$("#_purchaseUserIDs").html("");
	myApp.popup('.ModifyPurchaseUserID_box');
     //纯采购列表 9-26
    $.ajax({
        url: "/Team/GetPurchaseList",//提交地址   GetPurchasers
        type: "POST",//提交方式
        //data: "{'PageSize':'" + 100 + "','PageIndex':'" + 1 + "'}",
        data: "{'SysStatus':'" + 1 + "'}",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            var options = "";
            options += '<option value="">'+_("采购")+'</option>';
            if(_result.msgcode == false){
                options += '<option value="" >' + _(_result.msginfo)+ '</option>';                
                $("#_purchaseUserIDs").html(options);              
            }else{
                for (var i = 0; i < _result.length; i++) {
                    options += '<option value="' + _result[i].UserID + '"  >' + _result[i].RealName + '</option>';
                }
                $("#_purchasesUserIDs").html(options);
            }
        }
    });
}
//选采购
function ModifyPurchaseUserID() {   
	myApp.showPreloader(_("修改中，请稍等!"));
    //OrderIDs值组装 _orderIDs="232,324"
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }   
    $.ajax({
        url: "/Team/ModifyPurchaseUserID",//提交地址
        type: "POST",//提交方式
        data: "{'OrderIDs':'" + _orderIDs + "','PurchaseUserID':'" + $("#_purchasesUserIDs").val() + "'}",  //$("#test option:selected")
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
			myApp.hidePreloader();
			myApp.alert(_result["msginfo"],function(){
				 $('.ModifyPurchaseUserID_box').hide();
				 getOrder();
			});            
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){			
			myApp.hidePreloader();
			myApp.alert("网络超时，请重试");
		},
    });            
}

//供应商联系方式
function Contact_Js(me) {
	myApp.showIndicator();
    $.ajax({
        url: "/Team/ContactSupplier",//提交地址
        type: "POST",//提交方式
        data: "{'SupplierCode':'" + me.getAttribute("value") + "'}",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            if (_result.msgcode == false) {
                myApp.alert(_result.msginfo);
            } else {
                var _result = eval('(' + _result + ')');//再次解析_result

                if (_result.result == true) {
                    $("#_company").val(_result.Company);
                    $("#_shortName").val(_result.ShortName);
                    $("#_website").val(_result.Contact.Website);//json.json.json
                    $("#_qq").val(_result.Contact.QQ);
                    $("#_name").val(_result.Contact.Name); //Telephone 
                    $("#_telephone").val(_result.Contact.Telephone);
                    $("#_rapid").val(_result.Contact.RapID);
                    //$("#_skype").val(_result.Contact.Skype);
                    if (_result.Contact.Skype != "") {
                        $("#_skype").html("<b style='font-size:20px;' title='点击和" + _result.Contact.Skype + 
                        "聊天'><span><img src='https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1489148014986&di=253cba520b4b4c293c60f95cabd708db&imgtype=0&src=http%3A%2F%2Fimg.download.pchome.net%2F3p%2F7b%2Flogo.jpg' style='border: none;width:20px;height:20px;' /></span><label>" +
                        _result.Contact.Skype + "</label></b>");//点击打开Skype
                    } else {
                        $("#_skype").html("");
                    }
                    $("#_email").val(_result.Contact.Email);
                    $("#_wechat").val(_result.Contact.WeChat);
                    $("#_mobilephone").val(_result.Contact.MobilePhone);                  
                    $("#_address").val(_result.Address.Country + "-" + _result.Address.State + "-" + _result.Address.City);//中国-广东-深圳
                    myApp.popup(".Contact_box");
//                  $(".Contact_box").show();
                } else {
                    //暂无联系方式
                    myApp.alert(_("该供应商暂无联系方式"));
                }  
            }
            myApp.hideIndicator();
        }
    });
} 



//批量优惠、改价
function DiscountReturnEvent() {
	$("#DiscountReturn_box,#Discount_box").remove();
	var discountHtml=['<div class="form-group" id="DiscountReturn_box">',
                	'<label for="DiscountReturn">'+_("优惠退点")+'：</label>',
                	'<input class="form-control" type="text" id="_rebate" name="DiscountReturn" required="required" placeholder="'+_("优惠1个点输入-1")+'" />',
            	'</div>'].join('');
	$("#_discount_box").append(discountHtml);
}
function DiscountEvent() {
	$("#DiscountReturn_box,#Discount_box").remove();
	var discountHtml=['<div class="form-group" id="Discount_box">',
                '<label for="Discount">'+_("优惠折扣")+'：</label>',
                '<input class="form-control" type="text" id="_discount" required="required" name="Discount" placeholder="'+_("打85折输入0.85")+'" />',
            	'</div>'].join('');
	$("#_discount_box").append(discountHtml);
}
//批量优惠
function ReviseOrders_Js() {
    myApp.popup(".ReviseOrders_box");
	$("#_salesExchangerate").val(rate);
}
//批量优惠改价
function ReviseOrders() {
	myApp.showPreloader(_("修改中，请稍等!"));
    //模式 mode 1 （批量加点） 和 0  (批量折扣)
    //OrderIDs值组装 _orderIDs="232,324"
    var mode_type=$('#_revise input:radio[name="mode"]:checked').val();
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }
    var params={};
    params.OrderIDs=_orderIDs;
	params.Mode="0";
	params.SalesExchangerate=$("#_salesExchangerate").val();
	if(mode_type==1){//优惠退点
		params.Rebate=$("#_rebate").val();
	}else if(mode_type==0){//优惠折扣
		params.Discount=$("#_discount").val();
	}
    $.ajax({
        url: "/Team/ReviseOrders",//提交地址
        type: "POST",//提交方式
        data: JSON.stringify(params),
        timeout: 60000, //超时时间：30秒
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            myApp.hidePreloader();
			myApp.alert(_result.msginfo,function(){
				 $(".ReviseOrders_box input[type=reset]").trigger("click");//清空form数据 9-16 关键 一定要放最前面
				$(".ReviseOrders_box").hide();			
            	getOrder();//搜索订单8-28 
			});           
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();
			myApp.alert("网络超时，请重试");
		}
    });
}
//订单到货
function ArrivalOrders_Js() {
     // if(RoleID == 1 || RoleID == 5){
		myApp.popup(".ArrivalOrders_box");
    // }else{
    //     myApp.alert(_("【确认到货】禁用"));
    // }
}
 //订单到货（批量或单个）
function ArrivalOrders() {
    //仅管理员1和物流员5
	if($("#_arrivaltime_").val()=="")
		return false
	    myApp.confirm(_("【确认到货】确定要“确认到货”吗？"),function(){
	    	myApp.showPreloader(_("修改中，请稍等!"));
	        //OrderIDs值组装 _orderIDs="232,324"
	        var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
	        var _orderIDs = "";
	        for (var i = 0; i < orderlistCb.length; i++) {
	            if (i == 0)
	                _orderIDs += orderlistCb[i].lang;
	            else
	                _orderIDs += "," + orderlistCb[i].lang;
	        }
			var params={};
			params.OrderIDs=_orderIDs;
			params.ArrivalTime=$("#_arrivaltime_").val();
			params.ApplyID=UserID;
			
	        $.ajax({
	            url: "/Team/ArrivalOrders",
	            type: "POST",
	            data: JSON.stringify(params),
	            contentType: "application/json; charset=utf-8",
	            timeout: 30000, //超时时间：30秒
	            success: function (result) {
	                var _result = eval('(' + result + ')');	
	                myApp.hidePreloader();//隐藏加载中
	                if(_result.msgcode == true){
	                    myApp.alert(_(_result.msginfo),function(){
	                    	$(".ArrivalOrders_box").hide();
	                    	$(".ArrivalOrders_box input[type=reset]").trigger("click");//清空form数据	                    
	                    	getOrder();
	                    });	                  
	                }else{
	                    myApp.alert(_(_result.msginfo));
	                }
	            },
		        error: function(XMLHttpRequest, textStatus, errorThrown){
					myApp.hidePreloader();//隐藏加载中
					myApp.alert("网络超时，请重试");
				}
	        }); 
	    });
}

//订单作废
function CancelOrders_Js() {
	myApp.popup(".CancelOrders_box");
}
//作废订单
function CancelOrders() {
	myApp.showPreloader(_("修改中，请稍等!"));
    //OrderIDs值组装 _orderIDs="232,324"
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }
    $.ajax({
        url: "/Team/CancelOrders",//提交地址
        type: "POST",//提交方式
        data: "{'OrderIDs':'" + _orderIDs + "','SalesRemarks':'" + $("#_cancelRemarks").val() + "'}",
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            myApp.hidePreloader();
            if(_result.msgcode == true){
            	myApp.alert(_(_result.msginfo),function(){
            		$(".CancelOrders_box input[type=reset]").trigger("click");//清空form
            		$(".CancelOrders_box").hide();
            		getOrder();
            	});        
            }else{
                myApp.alert(_(_result.msginfo));
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
    });
}

//小数相减的精确值计算
function accSub(arg1,arg2){
    var r1,r2,m,n;
    try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
    try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
    m=Math.pow(10,Math.max(r1,r2));
    //last modify by deeka
    //动态控制精度长度
    n=(r1>=r2)?r1:r2;
    return ((arg1*m-arg2*m)/m).toFixed(n);
}
//解决0.01为0.1
function keepOneDecimalFull(num) {
    var result = parseFloat(num);
    if (isNaN(result)) {
        alert('传递参数错误，请检查！');
        return false;
    }
    result = Math.ceil(num * 10) / 10;
    var s_x = result.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += '.';
    }
    while (s_x.length <= pos_decimal + 1) {
        s_x += '0';
    }
    return s_x;
}

//收款账户
function PayOrders_Js(orderStatusValue,_Balance,_USDBalance,rmbMoney,usdMoney){
	$("#_pay :input").not("input[type=submit]").removeClass("error");		
    if (orderStatusValue == 7) {
        if (RoleID == 1 || RoleID == 2) {
            myApp.popup("#PayBackOrders_box");//退回供应商回款  7 已退回
            var requestJson={};
            requestJson.Status=1;
            requestJson.CheckResult=1;
            if(CurrentRMB==true && CurrentUSD==false){
            	requestJson.Currency=1;//人民币账户
            }else if(CurrentRMB==false && CurrentUSD==true){
            	requestJson.Currency=2;//人民币账户
            }
            //收款账户
            $.ajax({
                url: "/Team/GetBankList",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(requestJson),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象                        

                    var options = "";
                    options += '<option value="">'+_("选择账户")+'</option>';
                    for (var i = 0; i < _result.length; i++) {
                        options += '<option value="' + _result[i].BankID + '"  >【' + _result[i].BankName + '】' + CurrencyFormat(_result[i].Currency) + '</option>';
                    }
                    $("#_paybackBankID").html(options);
                }
            });
        } else {
            myApp.alert(_("【收款】禁用"));
        }

    } else {
      	myApp.popup("#PayOrders_box");//收客户款
        $('#arrivalTime_inp').hide();
        $('#remarks_inp').hide();
       GetBankList();
       $("#_currency option").remove();
		var $option = '<option value="" selected="selected">'+_("余额")+'</option>';
		if(CurrentRMB==true){
			$option+='<option value="1" class="CurrentRMB">￥:'+_Balance+'</option>';
		}		
		if(CurrentUSD==true){
			$option +='<option value="2" class="CurrentUSD">$:'+_USDBalance+'</option>';
		}           
	    $("#_currency").html($option);

        //充入金额
        var addBalance=accSub(rmbMoney,_Balance);
        var addusdBalance=accSub(usdMoney,_USDBalance);
        addBalance=keepOneDecimalFull(addBalance);
        addusdBalance=keepOneDecimalFull(addusdBalance);
        $("#_currency").change(function(){
            if($(this).val() == 1&&$(this).val() != ''){

                if(rmbMoney>_Balance){
                    $("#_chargingAmount").val(Math.ceil(addBalance));
                    $("#_optionBank").addClass("error");

                    $("#remarks_inp").show(); //备注
                    $("#arrivalTime_inp").show(); //到账日期
                    $("#_remarks2").addClass("error");
                    $("#_remarks2").prop("required",true);
                    $("#_remarks2").val('');

                }else{
                    $("#_chargingAmount").val('');
                    $("#_optionBank").removeClass("error");
                    $("#_optionBank").prop("required",false);

                    $("#remarks_inp").hide();
                    $("#arrivalTime_inp").hide();
                    $("#_remarks2").removeClass("error");
                    $("#_remarks2").prop("required",false);
                }
            }else if($(this).val() == 2&&$(this).val() != ''){

                if(usdMoney>_USDBalance){
                    $("#_chargingAmount").val(addusdBalance);
                    $("#_optionBank").addClass("error");

                    $("#remarks_inp").show();
                    $("#arrivalTime_inp").show();
                    $("#_remarks2").addClass("error");
                    $("#_remarks2").prop("required",true);
                    $("#_remarks2").val('');

                }else{
                    $("#_chargingAmount").val('');
                    $("#_optionBank").removeClass("error");
                    $("#_optionBank").prop("required",false);

                    $("#remarks_inp").hide();
                    $("#arrivalTime_inp").hide();
                    $("#_remarks2").removeClass("error");
                    $("#_remarks2").prop("required",false);
                }
            }else{
                $("#_chargingAmount").val('');
            }
        })

	    currentShow();
    }	
}
function GetBankList(){
	$("#_optionBank option").remove();
	var requestAccount = {};

	requestAccount.Status = 1; //启用1
	requestAccount.Type = '2,3'; //01-11 只要传了Type就不显示Type=2和3的账户 01-11
	if(CurrentRMB==true && CurrentUSD==false){
		requestAccount.Currency = 1; //人民币1 美金2
	}else if(CurrentRMB==false && CurrentUSD==true){
		requestAccount.Currency = 2; //人民币1 美金2
	}
	$.ajax({
		url: "/Team/GetBankList", //提交地址
		type: "POST", //提交方式
		async: false, //异步 9-27
		data: JSON.stringify(requestAccount),
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象

			if(_result.msgcode == false) {
				var options = "";
				options += '<lable>' + _result.msginfo + '</label>';
				$("#_optionBank").html(options);
			} else {
				options += '<option value="">'+_("选择账户")+'</option>';
                for (var i = 0; i < _result.length; i++) {
                    options += '<option value="' + _result[i].BankID + '"  >' + _(_result[i].BankName) + '</option>';
                }
				$("#_optionBank").html(options);
			}
		}
	});
}
//收款
function PayOrders(){
    myApp.confirm(_("【收款】确定要使用")+CurrencyFormat($("#_currency").val())+_("余额支付吗？"),function(){
    	myApp.showPreloader(_("修改中，请稍等!"));
        //OrderIDs值组装 _orderIDs="232,324"
        var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
        var _orderIDs = "";
        for (var i = 0; i < orderlistCb.length; i++) {
            if (i == 0)
                _orderIDs += orderlistCb[i].lang;
            else
                _orderIDs += "," + orderlistCb[i].lang;
        }
        var requestJson={};
        requestJson.OrderIDs=_orderIDs;
        requestJson.CustomerID=$("#_payCustID").html();
        requestJson.Currency=$("#_currency").val();
        requestJson.Amount = $("#_chargingAmount").val(); //充值金额
        requestJson.ArrivalTime = $("#_accountTime").val(); //到款日期
        requestJson.Account = $("#_optionBank").val(); //收款银行
        requestJson.Remarks=$("#_remarks2").val();// 备注
        requestJson.ApplyID=UserID;
		requestJson.ReviewID=UserID;
		requestJson.UserID=UserID;
        $.ajax({
            url: "/Team/PayAndRechargeOrders",
            type: "POST",
            data: JSON.stringify(requestJson),
            contentType: "application/json; charset=utf-8",
            timeout: 30000, //超时时间：30秒
            success: function (result) {
                var _result = eval('(' + result + ')');
                myApp.hidePreloader();
                if(_result.msgcode == true){
                    myApp.alert(_(_result.msginfo),function(){
                    	$(".PayOrders_box").hide();
                    	getOrder();//搜索订单 
                    });                   
                }else{
                    myApp.alert(_(_result.msginfo));
                }
            },
	        error: function(XMLHttpRequest, textStatus, errorThrown){
				myApp.hidePreloader();//隐藏加载中
				myApp.alert("网络超时，请重试");
			}
        });
    });
}        

//收款
function PayBackOrders_Js(){
	myApp.popup(".PayBackOrders_box");
}
function PayBackOrders(){
    myApp.confirm(_("【收款】确定要'收款'吗？"),function(){
    	myApp.showPreloader(_("修改中，请稍等!"));
        var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
        var _orderIDs = "";
        for (var i = 0; i < orderlistCb.length; i++) {
            if (i == 0)
                _orderIDs += orderlistCb[i].lang;
            else
                _orderIDs += "," + orderlistCb[i].lang;
        }
		var params={};
		params.OrderIDs=_orderIDs;
		params.BankID=$("#_paybackBankID").val();
		params.ArrivalTime=$("#paybackarrivalTime").val();
		params.PayBackAmount=$("#_paybackAmount").val();
		params.ApplyID=UserID ;
        $.ajax({
            url: "/Team/PayAndRechargeOrders",//提交地址
            type: "POST",//提交方式
            data: JSON.stringify(params),
            contentType: "application/json; charset=utf-8",
            timeout: 30000, //超时时间：30秒
            success: function (result) {
                var _result = eval('(' + result + ')');//eval()解析单个json对象
				myApp.hidePreloader();//隐藏加载中
                if(_result.msgcode == true){
                    myApp.alert(_(_result.msginfo),function(){
                    	$(".PayBackOrders_box").hide();
                   		getOrder();
                    });                   
                }else{
                    myApp.alert(_(_result.msginfo));
                }
            },
	        error: function(XMLHttpRequest, textStatus, errorThrown){
				myApp.hidePreloader();//隐藏加载中
				myApp.alert("网络超时，请重试");
			}
        });
    });
}

//付款账户
function ReceiptOrders_Js() {
	$("#_receiptBankID").html("");
     //仅管理员1 和 财务2

        myApp.popup(".ReceiptOrders_box");
        var requestJson={};
        requestJson.Status=1;
        requestJson.CheckResult=1;
        if(CurrentRMB==true && CurrentUSD==false){
        	requestJson.Currency=1;//人民币账户
        }else if(CurrentRMB==false && CurrentUSD==true){
        	requestJson.Currency=2;//人民币账户
        }
        //付款账户
        $.ajax({
            url: "/Team/GetBankList",//提交地址
            type: "POST",//提交方式
            data: JSON.stringify(requestJson),
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                var _result = eval('(' + result + ')');//eval()解析单个json对象                        
                var options = "";
                options += '<option value="">'+_("选择账户")+'</option>';
                for (var i = 0; i < _result.length; i++) {
                    options += '<option value="' + _result[i].BankID + '"  >【' + _result[i].BankName + '】' + _result[i].BankBalance + '' +
                    CurrencyFormat(_result[i].Currency) + '</option>';
                }                
                $("#_receiptBankID").html(options);
            }          
        });

}

//付款
function ReceiptOrders(){
	var bankId=$("#_receiptBankID").val();
	var amount=$("#_receiptAmount").val()
	var time=$("#receiptarrivalTime").val();
    //管理1和会计2

        myApp.confirm(_("确定各项参数无误,'付款'吗？"),function(){
        	myApp.showPreloader(_("修改中，请稍等!"));
            //OrderIDs值组装 _orderIDs="232,324"
            var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
            var _orderIDs = "";
            for (var i = 0; i < orderlistCb.length; i++) {
                if (i == 0)
                    _orderIDs += orderlistCb[i].lang;
                else
                    _orderIDs += "," + orderlistCb[i].lang;
            }
			
			var params={};
			params.OrderIDs=_orderIDs
			params.BankID=bankId;
			params.ReceiptAmount=amount;
			params.ArrivalTime=time;
			params.ApplyID=UserID;
            $.ajax({
                url: "/Team/ReceiptOrders",
                type: "POST",
                data: JSON.stringify(params),    
                contentType: "application/json; charset=utf-8",
                timeout: 30000, //超时时间：30秒
                success: function (result) {
                    var _result = eval('(' + result + ')');
                    myApp.hidePreloader();
                    if(_result.msgcode == true){
						myApp.alert(_(_result.msginfo),function(){
							$(".ReceiptOrders_box").hide();
                        	$(".ReceiptOrders_box input[type=reset]").trigger("click");//清空form                        
                       		getOrder(); 
						});                       
                    }else{
                        myApp.alert(_(_result.msginfo));
                    }
                },
		        error: function(XMLHttpRequest, textStatus, errorThrown){
					myApp.hidePreloader();//隐藏加载中
					myApp.alert("网络超时，请重试");
				}
            });
        });

}
//部分金额输入项
function PayAmountNum(){
    myApp.confirm(_("【部分付】必须满足以下两个条件 \n\n （1）部分付仅允许选中1条订单 \n （2）部分金额必输 \n\n不同时满足上述两条件，按【全部付】处理"),function(){
        $("#_receiptAmount").removeAttr("disabled");   
    });
}
//订单备注
function RemarkOrder_Js(){
	myApp.popup(".RemarkOrder_box");
}
//备注订单
function RemarkOrder() {
	myApp.showPreloader(_("修改中，请稍等!"));
	var remarks=$("#_remarks").val()
	var saleremark=$("#_salesRemarks").val()
	var purremark=$("#_purchaseRemarks").val()
	var goodremark=$("#_goodsRemark").val()
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }
    var params={};
    params.OrderIDs=_orderIDs;
    params.Remarks=remarks
    params.SalesRemarks=saleremark
    params.PurchaseRemarks=purremark
    params.GoodsRemark=goodremark;
    $.ajax({
        url: "/Team/RemarkOrder",//提交地址
        type: "POST",//提交方式
        data: JSON.stringify(params),
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            myApp.hidePreloader();
			if(_result.msgcode==true){
				myApp.alert(_(_result.msginfo),function(){
					$(".RemarkOrder_box").hide();
					getOrder();
				});
			}else{
				myApp.alert(_(_result.msginfo));
			}		
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
    }); 
}
//申请充值
function ApplyFlow_Js(id){
	myApp.popup(".Balance_box");
	  $.ajax({
        url: "/Customer/GetCustomerInfo",//提交地址
        type: "POST",//提交方式
        data: "{'CustomerID':'" + id + "'}",
        contentType: "application/json; charset=utf-8",
        
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象              
            //客户申请余额            
            $("#_custID").val(_result.CustomerID);
            $("#_realName").val(_result.UserName);
            $("#_bal").val(_result.Balance);
        }
    });

    CzAccountLoad();//账户列表 12-21
}
 //确定申请充值
function ApplyFlow(){
	myApp.showPreloader(_('提交中，请耐心等候...'));
    var requestFlow = {};
    requestFlow.CustomerID = $("#_custID").val();//客户ID
    requestFlow.ApplyID = $.cookie("UserID");
    requestFlow.Remarks = $("#cremarks").val();
    requestFlow.Amount = $("#camount").val();   
    requestFlow.ArrivalTime = $("#carrivalTime").val();
    requestFlow.Type = 1; //定金1（收入） 提现2（支出）
    requestFlow.Abstract = 2;//操作类型(摘要) 1.出货全款 2.定货款/尾款
    requestFlow.Currency = 1;//币种 1.人民币 2.美元
    requestFlow.Status = 0;//0待审核 1已审核 -1 已作废
    //requestFlow.Account =$('input:radio[name="Account"]:checked').val(); 
    requestFlow.Account =$('#_bankID1 input:radio[name="Account"]:checked').val(); //动态radio 12-21

    $.ajax({
        url: "/Team/AddFlow",
        type: "POST",
        data: JSON.stringify(requestFlow),
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            myApp.hidePreloader();
        	if (_result.msgcode == true) {
                myApp.alert(_result.msginfo,function(){
                	$(".Balance_box input[type=reset]").trigger("click");//清空form数据 12-10
                	$(".Balance_box").hide();
                	//window.location.href = "/team/apply";//申请 12-9                	
                });                
            } else {                            
                myApp.alert(_(_result.msginfo));//失败
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
    });
}
//申请美金充值
function ApplyUSDFlow_Js(id){
	myApp.popup(".USDBalance_box");
	 CzUSDAccountLoad();//账户列表 12-21
    $.ajax({
        url: "/Customer/GetCustomerInfo",
        type: "POST",
        data: "{'CustomerID':'" + id+ "'}",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');     
            //客户申请余额
            $("#_cuID").val(_result.CustomerID);
            $("#_cID").val(_result.CustomerID);
            $("#_reName").val(_result.UserName);
            $("#_usdbal").val(_result.USDBalance);

        }
    });
}
 //确定申请美金充值
function ApplyUSDFlow(){
	myApp.showPreloader(_('提交中，请耐心等候...'));
    var requestUSDFlow = {};
    requestUSDFlow.CustomerID = $("#_cuID").val();//客户ID
    requestUSDFlow.ApplyID = $.cookie("UserID");
    requestUSDFlow.Remarks = $("#cusdremarks").val();
    requestUSDFlow.Amount = $("#cusdamount").val();   
    requestUSDFlow.ArrivalTime = $("#cusdarrivalTime").val();
    requestUSDFlow.Type = 1; //定金1（收入） 提现2（支出）
    requestUSDFlow.Abstract = 2;//操作类型(摘要) 1.出货全款 2.定货款/尾款
    requestUSDFlow.Currency = 2;//币种 1.人民币 2.美元
    requestUSDFlow.Status = 0;//0待审核 1已审核 -1 已作废

    //requestUSDFlow.Account =$('input:radio[name="Account"]:checked').val(); 
    requestUSDFlow.Account =$('#_usdbankID input:radio[name="Account"]:checked').val(); //动态radio 12-21

    $.ajax({
        url: "/Team/AddFlow",
        type: "POST",
        data: JSON.stringify(requestUSDFlow),
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');
			 myApp.hidePreloader();
            if (_result.msgcode == true) {
            	 myApp.alert(_(_result.msginfo),function(){
                	$(".USDBalance_box input[type=reset]").trigger("click");//清空form数据
                	 $(".USDBalance_box").hide();
                	//window.location.href = "/team/apply";//申请 12-9                	
               });    
            } else {                            
                myApp.alert(_(_result.msginfo));//失败
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
    });
}
//申请Cz美金充值账户列表
function CzUSDAccountLoad() {
	 $("#_usdbankID").html("");
    var requestAccount = {};
    requestAccount.Status = 1;//启用1
    requestAccount.Type = '2,3';//01-11 只要传了Type就不显示Type=2和3的账户 01-11
    requestAccount.Currency = 2;//01-11 人民币1 美金2
    $.ajax({
        url: "/Team/GetBankList",
        type: "POST",
        async: false, 
        data: JSON.stringify(requestAccount),
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');
            if (_result.msgcode == false) {
                var options = "";                
                options += '<lable>' + _(_result.msginfo) + '</label>';               
                $("#_usdbankID").html(options);
            } else {
                var options = "";
                for (var i = 0; i < _result.length; i++) {
                    options += '<label style="width:auto" for="czaccout' + i + '">'+
                    '<input type="radio" name="Account" value="' + _result[i].BankID + '" id="czaccout' + i + '" />' + _(_result[i].BankName) + '</label>';
                }
                $("#_usdbankID").html(options);
            }
        }
    });
}
//申请Cz充值账户列表 
function CzAccountLoad() {
	$("#_bankID1").html("");
    var requestAccount = {};
    requestAccount.Status = 1;//启用1
    requestAccount.Type = '2,3';//01-11 只要传了Type就不显示Type=2和3的账户 01-11
    requestAccount.Currency = 1;//01-11 人民币1 美金2
    $.ajax({
        url: "/Team/GetBankList",//提交地址
        type: "POST",//提交方式
        async: false, //异步 9-27
        data: JSON.stringify(requestAccount),
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象

            if (_result.msgcode == false) {
                var options = "";
                options += '<lable>' + _(_result.msginfo) + '</label>';
                $("#_bankID1").html(options);
            } else {
                var options = "";
                for (var i = 0; i < _result.length; i++) {
                    options += '<label style="width:auto" for="czaccout' + i + '">'+
                    '<input type="radio" name="Account" value="' + _result[i].BankID + '" id="czaccout' + i + '" />' + _(_result[i].BankName) + '</label>';
                }
                $("#_bankID1").html(options);
            }
        }
    });
}
//取消到货
function CancelArrivalOrders_Js() {
    //仅管理员1和物流员5
    // if(RoleID == 1 || RoleID == 5){
        myApp.confirm(_("【取消到货】确定要“取消到货”吗？"),function(){
        	myApp.showPreloader(_("修改中，请稍等!"));
            var requestCancel = {};
            var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
            var _orderIDs = "";
            for (var i = 0; i < orderlistCb.length; i++) {
                if (i == 0)
                    _orderIDs += orderlistCb[i].lang;
                else
                    _orderIDs += "," + orderlistCb[i].lang;
            }
            requestCancel.OrderIDs = _orderIDs;
            requestCancel.ApplyID =UserID;
            $.ajax({
                url: "/Team/CancelArrivalOrders",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(requestCancel),
                contentType: "application/json; charset=utf-8",
                timeout: 30000, //超时时间：30秒
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                    myApp.hidePreloader();//隐藏加载中
                    if(_result.msgcode == true){
                        myApp.alert(_(_result.msginfo));
                        getOrder();
                    }else{
                        myApp.alert(_(_result.msginfo));
                    }
                },
		        error: function(XMLHttpRequest, textStatus, errorThrown){
					myApp.hidePreloader();//隐藏加载中
					myApp.alert("网络超时，请重试");
				}
            });
        });               

    // }else{
    //     myApp.alert(_("【取消到货】禁用"));
    // }
}


//采购汇率
function ExchangeOrders_Js(){
	myApp.popup(".ExchangeOrders_box");  
}
function ExchangeOrders(){
	myApp.showPreloader(_("修改中，请稍等!"));
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }
    var params={}
    params.OrderIDs=_orderIDs;
    params.PurchaseExchangerate=$("#_PurchaseExchangerate").val();
   
     $.ajax({
        url: "/Team/ExchangeOrders",//提交地址
        type: "POST",//提交方式
        data: JSON.stringify(params),
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            myApp.hidePreloader();//隐藏加载中            
            if(_result.msgcode == true){
                myApp.alert(_(_result.msginfo));
                $(".ExchangeOrders_box").hide();
                getOrder();
            }else{
                myApp.alert(_(_result.msginfo));
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
     });
}
//修改运费
function ModFreight_Js() {
	myApp.popup(".ModFreight_box");
}
 //修改运费
function ModFreight(){
	myApp.showPreloader(_("修改中，请稍等!"));
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }

    $.ajax({
        url: "/Team/ModFreight",//提交地址
        type: "POST",//提交方式
        data: "{'OrderIDs':'" + _orderIDs + "','Freight':'"+ $("#_freight").val() +"'}",
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            myApp.hidePreloader();//隐藏加载中
            if(_result.msgcode == true){               
                myApp.alert(_(_result.msginfo),function(){
                	$(".ModFreight_box input[type=reset]").trigger("click");//清空form数据 11-11 关键 一定要放最前面
                	$(".ModFreight_box").hide();
                	getOrder();
                });              
            }else{
                myApp.alert(_(_result.msginfo));
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
    });     
}
//预先制作出货单
function AddShip_Js(){
    myApp.confirm(_("确定要预先制作出货单吗？"),function(){
        var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
        var _orderIDs = "";
        for (var i = 0; i < orderlistCb.length; i++) {
            if (i == 0)
                _orderIDs += orderlistCb[i].lang;
            else
                _orderIDs += "," + orderlistCb[i].lang;
        }

        $.ajax({
            url: "/Team/AddShip",//提交地址
            type: "POST",//提交方式
            data: "{'OrderIDs':'" + _orderIDs + "'}",
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                var _result = eval('(' + result + ')');//eval()解析单个json对象
                myApp.alert(_(_result.msginfo));
                getOrder();
            }           
        });
    });
}
//订单出货
function EditShip_Js(){
	myApp.popup(".EditShip_box");
}
//出货
function EditShip() {
	myApp.showPreloader(_("修改中，请稍等!"));
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }
    $.ajax({
        url: "/Team/Shipment",//提交地址
        type: "POST",//提交方式
        data: "{'OrderIDs':'" + _orderIDs + "','ShipRemarks':'" + $("#_shipRemarks").val() + "'}",
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
			myApp.hidePreloader();//隐藏加载中
            if(_result.msgcode == true){
            	myApp.alert(_(_result.msginfo),function(){
            		$(".EditShip_box").hide();
                	$(".EditShip_box input[type=reset]").trigger("click");//清空form
                	getOrder();
            	});           	
            }else{
                myApp.alert(_(_result.msginfo));
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
    });
}   

//打印出货单
function PrintShip(){
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }

    $.ajax({
        url: "/Team/PrintShipOrders",//提交地址
        type: "POST",//提交方式
        data: "{'OrderIDs':'" + _orderIDs + "'}",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象

            if (_result.msgcode == true) {
                window.open(_result.msginfo);//打开文件
                myApp.alert(_("订单下载成功.如未自动下载，请查看文件是否被浏览器拦截。"));
            } else {
                myApp.alert(_(_result.msginfo));
            }

        }
    });
}
//自留变现
function StockOrders_Js(){
    //用户数组start
    selnamelist = {};//用户数组
    for (var i = 0; i < $("#stock_body .check_list_box span.selected").size() ; i++) {//得到所有选中的行
        var _skey = $("#stock_body .check_list_box span.selected").eq(i).parent().attr("lang");//得到当前选中的行
        selnamelist[_skey] = _skey;//用户数组
    }
    var sleng = 0;//主要用来做首行判断
    var samename = true;//是否是同一用户
    var sfirst = 0;//第一个用户记录
    for (var ss in selnamelist) {
        if (sleng == 0)//用户记录
            sfirst = selnamelist[ss];
        else {
            if (selnamelist[ss] != sfirst) {//当前用户与首次不同
                samename = false;
                break;
            }
        }
        sleng++;
    }
    if (samename) {
        //通过
        $("#_stockCustomerID").html(sfirst);//CustomerID 12-28
        myApp.popup(".StockOrders_box");
    } else {
        myApp.alert(_("【自留变货】选择不当！请选择“同一客户”的订单"));
    }
    //用户数组end
}

 //自留订单
function StockOrders() {
	myApp.showPreloader(_("修改中，请稍等!"));
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }
    var requestJson={};
    requestJson.OrderIDs=_orderIDs;
    requestJson.SalesRemarks=$("#_stockRemarks").val();
    requestJson.SalesUserID=UserID;
    requestJson.CustomerID=$("#_stockCustomerID").html();
    $.ajax({
        url: "/Team/StockOrders",
        type: "POST",
        data: JSON.stringify(requestJson),
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            myApp.hidePreloader();//隐藏加载中
            if(_result.msgcode == true){
            	myApp.alert(_(_result["msginfo"]),function(){
            		$(".StockOrders_box input[type=reset]").trigger("click");//清空form
            		$(".StockOrders_box").hide();
            		getOrder();//搜索订单8-28 
            	});             
            }else{
                myApp.alert(_(_result.msginfo));
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
    });
}

//退回供应商
function ReturnOrders_Js(){
    //点击退回事件 12-28
    //用户数组start
    selnamelist = {};//用户数组
    for (var i = 0; i < $("#stock_body .check_list_box span.selected").size() ; i++) {//得到所有选中的行
        var _skey = $("#stock_body .check_list_box span.selected").eq(i).parent().parent().attr("lang");//得到当前选中的行
        var _supplier=$("#stock_body .check_list_box span.selected").eq(i).parent().parent().attr("data-supplier");

        if(_supplier=="YDT"){
            myApp.alert("【退回供应商】"+_("不能选择现货的订单退回"));
            return false;
        }
        selnamelist[_skey] = _skey;//用户数组
    }
    var sleng = 0;//主要用来做首行判断
    var samename = true;//是否是同一用户
    var sfirst = 0;//第一个用户记录
    for (var ss in selnamelist) {
        if (sleng == 0)//用户记录
            sfirst = selnamelist[ss];
        else {
            if (selnamelist[ss] != sfirst) {//当前用户与首次不同
                samename = false;
                break;
            }
        }
        sleng++;
    }
    if (samename) {
        //通过
        $("#_returnCustomerID").html(sfirst);//CustomerID 12-28
        myApp.popup(".ReturnOrders_box");
    } else {
        myApp.alert(_("【退回供应商】选择不当！请选择“同一客户”的订单"));
    }
    //用户数组end   
}
//退回订单
function ReturnOrders() {
	myApp.showPreloader(_("修改中，请稍等!"));
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }
    var requestJson={};
    requestJson.OrderIDs=_orderIDs;
    requestJson.SalesRemarks=$("#_returnRemarks").val();
    requestJson.SalesUserID=UserID;
    requestJson.CustomerID=$("#_returnCustomerID").html();
    $.ajax({
        url: "/Team/ReturnOrders",//提交地址
        type: "POST",//提交方式
        data: JSON.stringify(requestJson),//_returnRemarks退回
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
			myApp.hidePreloader();//隐藏加载中
            if(_result.msgcode == true){
            	myApp.alert(_(_result["msginfo"]),function(){
            		$(".ReturnOrders_box input[type=reset]").trigger("click");//清空form
            		$(".ReturnOrders_box").hide();
            		getOrder();
            	});            
            }else{
                myApp.alert(_(_result.msginfo));
            }                   
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
    });
}        

//采购订单
function PurchaseOrder(me) {  
	myApp.showPreloader(_("修改中，请稍等!"));
    computeUsd();//确定之前已退点为准再计算一次 10-15

    var requestOrder = {};
    requestOrder.OrderID = $("#_orderID").val();
    requestOrder.OrderStatus = $("#_orderStat").val();//11-3
    requestOrder.Shape    =$("#_shape").val();            
    requestOrder.Weight    =$("#_weight").val();
    requestOrder.IsFancy    =$("#_isFancy").val();
    if($("#_isFancy").val() ==0){
        requestOrder.Color    =$("#e_color").val();
    }else{
        requestOrder.Color    =$("#e_fancycolor").val();
    }
    requestOrder.Clarity    =$("#e_clarity").val();
    requestOrder.Cut    =$("#_cut").val();
    requestOrder.Polish =$("#_polish").val();
    requestOrder.Symmetry =$("#_symmetry").val();
    requestOrder.Fluorescence =$("#_fluorescence").val();
    requestOrder.CertType =$("#_certType").val();
    requestOrder.CertNo =$("#_certno").val().trim();           
    requestOrder.SupplierCode = $("#_supplierCodeValue").val(); //采购部分 10-27
    requestOrder.DiscountReturn =  $("#_discountReturn").val().trim();//退点
    requestOrder.PriceUSD = $("#_priceUSD").val().trim();//美金总价
    requestOrder.OriginSN = $("#_originSN").val();
    requestOrder.DeliveryTime = $("#_deliveryTime").val();
    requestOrder.PurchaseRemarks =  $("#_purchasesRemarks").val();
    requestOrder.PurchaseExchangerate =  $("#_purchaseExchange").val();//采购汇率
    requestOrder.PurchaseRMB =  $("#_purchaseRMB").val();//采购RMB
	if(requestOrder.Weight=="" || requestOrder.Shape=="" || requestOrder.Clarity=="" || requestOrder.SupplierCode=="" || requestOrder.DiscountReturn==""
		|| requestOrder.PriceUSD=="" || requestOrder.CertNo==""|| requestOrder.DeliveryTime=="" || requestOrder.PurchaseRemarks ==""){
			return false;
			myApp.hidePreloader();
		}
		
    $.ajax({
        url: "/Team/PurchaseOrder",
        type: "POST",
        data: JSON.stringify(requestOrder),
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');
            myApp.hidePreloader();
            myApp.alert(_(_result.msginfo),function(){
            	$(".modify_pop_box").hide();
            	getOrder();  
            });                          
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
    });
}

 //采购订单，根据退点算美金总价(默认4C不变)
function computeUsd(){
    var weight =$("#_weight").val();
    var rapnet =$("#_rapnet").val();
    var isfancy =$("#_isFancy").val();
    var discount =$("#_discountReturn").val();
    if(isfancy == 0){
        if(discount != ""){
            if (discount >= 0) {
                discount = 100 + Math.abs(discount);
            }
            else {
                discount = 100 - Math.abs(discount);
            }
            var priceusd = weight * rapnet * (discount) / 100;//美金总价priceusd
        }
        $("#_priceUSD").val(priceusd); //美金总价
    }else{
        //不变
    }
}

 //单个改价
 function DiscountReturnEvent_one() {
  $("#DiscountReturn_box").show();
    $("#Confirmdiscount_box").show();


    $("#Discount_box").hide();
    $("#ConfirmPrice_box").hide();
    $("#ConfirmPrice_boxUSD").hide();
}
function DiscountEvent_one() {
    $("#DiscountReturn_box").hide();
    $("#Confirmdiscount_box").hide();
    $("#ConfirmPrice_boxUSD").hide();

    $("#Discount_box").show();
    $("#ConfirmPrice_box").show();
}
function DiscountEvent_one_usd() {
    $("#DiscountReturn_box").hide();
    $("#Confirmdiscount_box").hide();
    $("#ConfirmPrice_box").hide();

//  $("#Discount_box").show();
    $("#ConfirmPrice_boxUSD").show();
}
//单个改价
function ReviseAnOrder_Js(me) {
    myApp.popup(".ReviseAnOrder_box");
    //订单信息
    $.ajax({
        url: "/Team/GetOrderInfo",//提交地址
        type: "POST",//提交方式
        data: "{'OrderID':'" + me.getAttribute("value") + "'}",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
			if(_result.msgcode == true){
				var _result = _result.msginfo;
				//基本信息
				$("#_anorderid").val(_result.OrderID);
				$("#_salesRate").val(_result.SalesExchangerate);
	
				$("#_confirmdiscount").val(_result.Confirmdiscount);
				$("#_confirmPrice").val(formatRMBPrice(_result.ConfirmPrice));
				$("#_confirmPriceUSD").val(formatUSDPrice(_result.ConfirmUSD));
				$("#_BEFPrice").val(Math.round(_result.ConfirmPrice / _result.SalesExchangerate));
			}else{
				$(".ReviseAnOrder_box").hide();
				toast(_(_result.msginfo));
			}			

        }
    });
}

//批量优惠
function ReviseAnOrder(){	
    //模式 model 1 （总价） 和 0  (退点)
	var params={};
	params.OrderID=$("#_anorderid").val();
	params.Mode=$('input:radio[name="model"]:checked').val();
	params.SalesExchangerate=$("#_salesRate").val();
	params.Confirmdiscount=$("#_confirmdiscount").val();
	params.ConfirmPrice=$("#_confirmPrice").val();
	params.ConfirmUSD=$("#_confirmPriceUSD").val();
	if(params.Confirmdiscount=="" || params.ConfirmPrice==""|| params.ConfirmUSD=="")
		return false;
	myApp.showPreloader(_("修改中，请稍等!"));
    $.ajax({
        url: "/Team/ReviseAnOrder",
        type: "POST",
        data: JSON.stringify(params),
        timeout: 30000, //超时时间：30秒
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');
            myApp.hidePreloader();
            myApp.alert(_(_result.msginfo),function(){
            	$(".ReviseAnOrder_box").hide();
          		getOrder();//加载订单列表
            });
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();
			myApp.alert("网络超时，请重试");
		},
    });
}
//删除
function DelOrders_Js(){
    myApp.popup(".DelOrders_box");
    //仅管理员
     $("#del_btn").attr("disabled","disabled");                
        if(RoleID == 1){
        $("#del_btn").removeAttr("disabled");
    }
}
    
//订单删除
function DelOrders(){         
	myApp.showPreloader(_("修改中，请稍等!"));
    //OrderIDs值组装 _orderIDs="232,324"
    var orderlistCb = $("#stock_body .check_list_box span.selected");//checked的
    var _orderIDs = "";
    for (var i = 0; i < orderlistCb.length; i++) {
        if (i == 0)
            _orderIDs += orderlistCb[i].lang;
        else
            _orderIDs += "," + orderlistCb[i].lang;
    }

    $.ajax({
        url: "/Team/DelOrders",//提交地址
        type: "POST",//提交方式
        data: "{'OrderIDs':'" + _orderIDs + "'}",
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            myApp.hidePreloader();
            myApp.alert(_("成功")+_result.succ+","+_("失败")+_result.fail);
        	$(".DelOrders_box").hide();
        	getOrder();//搜索订单
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
    });           
}

//回裸钻库
function BackDia(me) {
	var finalRes = $('#_backdia').serializeArray().reduce(function(result, item){
	result[item.name] = item.value;
	return result;
	}, {})//把提交的数据转为JSON格式
	//禁用输入框另外写
	var SourceDolarPerCarat = Number($("#sourceDolarPerGrain").val())//Number($("#weight").val());
	finalRes.SourceDiscountReturn = $("#sourceDiscountReturn").val();
	finalRes.SourceDolarPerGrain = $("#sourceDolarPerGrain").val();
	finalRes.SourceDolarPerCarat = SourceDolarPerCarat;
	finalRes.BuyUSDPrice = $("#back_purchaseUSDPerGrain").val(); //买美金
	finalRes.BuyRMBPrice = $("#back_purchaseRmbPerGrain").val(); //买人民币
	finalRes.PurchaseExchangerate = $("#SaleseRate").val(); //买汇率
	finalRes.CertNo=$("#certNo").val();
	finalRes.CertType=$("#certType").val();
	finalRes.PurchaseSupplier=$("#back_purchaseSupplier").val();
	//订单信息
	console.log(finalRes)
	$.ajax({
		url: "/Team/AddDia", //提交地址 team/updateOrder
		type: "POST", //提交方式
		data: JSON.stringify(finalRes),
		contentType: "application/json; charset=utf-8",
		success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            
            if (_result.msgcode == false) {
                //添加失败(接口错误或程序内部错误)
                myApp.alert(_("新增失败")+"：" + _(_result.msginfo));
            } else {
                //添加成功
                if (_result.result == true) {
                    //{\"count\": 1, \"ids_insert\": [5158997], \"ids\": [5158997], \"ids_update\": [], \"result\": true, \"count_update\": 0, \"count_insert\": 1}
                    myApp.alert(_("成功条目")+"：" + _result.count + _("\n\n新增条目")+"：" + _result.count_insert + _("\n\n更新条目")+"：" + _result.count_update);
//                          $(".BackDia_box").hide();//回库框关闭
                    myApp.closeModal(".BackDia_box");
                    getOrder();
                } else {
                    //请求参数不符{\"msg\": \"\\u4ef7\\u683c\\u8f6c\\u6362\\u5931\\u8d25\", \"result\": false}
                    myApp.alert(_("新增失败")+"：" + _(_result.msg));
                }
            }
        }
		
	});
}
        
//自留回库
function BackDia_Js(me,gwRate) {
	//回库供应商
    var Supplier = "";
    $.ajax({
        url: "/Team/GetOrderInfo",//提交地址
        type: "POST",//提交方式
        data: "{'OrderID':'" + me.getAttribute("value") + "'}",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            if(_result.msgcode==true){
            	_result = _result.msginfo;
            	//所在地
				var val = _result.IsFancy;
			    var html_Place='';
				for (var i = 0; i < stock[val].Place.length; i++) {
					html_Place +='<option value="'+stock[val].Place[i][0]+'">'+ _(stock[val].Place[i][1]) +'</option>';
				}	
				$("#place").html(html_Place);
				myApp.popup(".BackDia_box"); 
				$("#_backdia").setForm(_result);//绑数据 
				//时间格式化
				$("#back_PurchaseTime").val($.trim(YearDateFormat2(new Date())));
				$("#back_ArrivalTime").val($.trim(YearDateFormat2(_result.ArrivalTime)));
				//回库供应商
	            if(_result.PurchaseSupplier){
	            	Supplier = _result.PurchaseSupplier;
	            }else if(_result.SupplierCode){
	            	Supplier = _result.SupplierCode;
	            }else{
	            	$("#back_purchaseSupplier").prop("disabled",false);  //都为空值则可填写
	            }
	            $("#back_purchaseSupplier").val(Supplier);//01-12
	            
            }else{
                myApp.alert(_(_result.msginfo));     	
           	}
            
        }
    });
}

//批量修改所在地
function ModifyPlace() {
	myApp.showPreloader(_("修改中，请稍等!"));
	var request = {};
	IDs = "";
	var inventorylistCb = $("#stock_body .check_list_box span.selected"); //checked的
	for(var i = 0; i < inventorylistCb.length; i++) {
		IDs +=  inventorylistCb[i].lang+",";
	}
	IDs = IDs.substring(0, IDs.lastIndexOf(','));
	request.OrderIds = IDs;
	request.Place = $("#_batchplace").val();
	$.ajax({
		url: "/team/UpdatePlace", //提交地址/Team/BatchUpdateDia
		type: "POST", //提交方式
		data: JSON.stringify(request),
		contentType: "application/json; charset=utf-8",
		timeout: 30000, //超时时间：30秒
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象
			myApp.hidePreloader();//隐藏加载中
			if(_result.msgcode == true) {
				myApp.alert(_(_result.msginfo) );
				$(".ModPlace_box").hide();
				getOrder(); //订单搜索
			} else {
				myApp.alert(_(_result.msginfo) ); //编辑失败                        
			}
		},
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
	});
}

//批量修改货品状态
function ModifyStatus() {
    myApp.showPreloader(_("修改中，请稍等!"));
    var request = {};
    IDs = "";
    var inventorylistCb = $("#stock_body .check_list_box span.selected"); //checked的
    for(var i = 0; i < inventorylistCb.length; i++) {
        IDs +=  inventorylistCb[i].lang+",";
    }
    IDs = IDs.substring(0, IDs.lastIndexOf(','));
    request.OrderIDs = IDs;
    request.Status = $("#_batchstatus").val();
    $.ajax({
        url: "/team/UpdateStatus", //提交地址/Team/BatchUpdateDia
        type: "POST", //提交方式
        data: JSON.stringify(request),
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function(result) {
            var _result = eval('(' + result + ')'); //eval()解析单个json对象
            myApp.hidePreloader();//隐藏加载中
            if(_result.msgcode == true) {
                myApp.alert(_(_result.msginfo) );
                $(".ModStatus_box").hide();
                getOrder(); //订单搜索
            } else {
                myApp.alert(_(_result.msginfo) ); //编辑失败
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            myApp.hidePreloader();//隐藏加载中
            myApp.alert("网络超时，请重试");
        }
    });
}

//批量修改原供应商
function ModifyPurchaseSupplier() {
	myApp.showPreloader(_("修改中，请稍等!"));
	var request = {};
	IDs = "";
	var inventorylistCb = $("#stock_body .check_list_box span.selected"); //checked的
	for(var i = 0; i < inventorylistCb.length; i++) {
		IDs +=  inventorylistCb[i].lang+",";
	}
	IDs = IDs.substring(0, IDs.lastIndexOf(','));
	request.OrderIds = IDs;
	request.PurchaseSupplier = $("#_purchaseSupplier").val();
	$.ajax({
		url: "/team/UpdatePurchaseSupplier", //提交地址/Team/BatchUpdateDia
		type: "POST", //提交方式
		data: JSON.stringify(request),
		contentType: "application/json; charset=utf-8",
		timeout: 30000, //超时时间：30秒
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象
			myApp.hidePreloader();//隐藏加载中
			if(_result.msgcode == true) {
				myApp.alert(_(_result.msginfo) );
				$(".ModPurchaseSupplier_box").hide(); //删除框关闭
				getOrder(); //订单搜索
			} else {
				myApp.alert(_(_result.msginfo) ); //编辑失败                              
			}
		},
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
	});
}

//修改买价
function ModifyPurchasePrice(val){
	myApp.showPreloader(_("修改中，请稍等!"));
	var request = {};
	IDs = "";
	var inventorylistCb = $("#stock_body .check_list_box span.selected"); //checked的
	for(var i = 0; i < inventorylistCb.length; i++) {
		IDs +=  inventorylistCb[i].lang+",";
	}
	IDs = IDs.substring(0, IDs.lastIndexOf(','));
	request.OrderIds = IDs;
	request.power = Number($("#_purchasePrice").val());
	if(val==1){
		var submitUrl="/team/updatePriceUSD";
	}else if(val==2){
		var submitUrl="/team/updateBuyUSDPrice";
	}
	$.ajax({
		url: submitUrl, //提交地址
		type: "POST", //提交方式
		data: JSON.stringify(request),
		contentType: "application/json; charset=utf-8",
		timeout: 30000, //超时时间：30秒
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象
			myApp.hidePreloader();//隐藏加载中
			if(_result.msgcode == true) {
				$(".ModPurchasePrice_box").hide();
				myApp.alert(_(_result.msginfo) );				
				getOrder(); //订单搜索
			} else {
				myApp.alert(_(_result.msginfo) ); //编辑失败                              
			}
		},
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
	});
}
//修改采购汇率
function ModifyPurchaseExchangerate(){
	myApp.showPreloader(_("修改中，请稍等!"));
	var request = {};
	IDs = "";
	var inventorylistCb = $("#stock_body .check_list_box span.selected"); //checked的
	for(var i = 0; i < inventorylistCb.length; i++) {
		IDs +=  inventorylistCb[i].lang+",";
	}
	IDs = IDs.substring(0, IDs.lastIndexOf(','));
	request.OrderIds = IDs;
	request.PurchaseExchangerate = $("#_PurchaseExchangerate").val();
	$.ajax({
		url: "/team/updatePurchaseExchangerate", //提交地址/Team/BatchUpdateDia
		type: "POST", //提交方式
		data: JSON.stringify(request),
		contentType: "application/json; charset=utf-8",
		timeout: 30000, //超时时间：30秒
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象
			if(_result.msgcode == true) {
				$(".ModPurchaseExchangerate_box").hide();
                myApp.hidePreloader();//隐藏加载中
				myApp.alert(_(_result.msginfo));				
				getOrder(); //订单搜索
			} else {
				myApp.alert(_(_result.msginfo) );                        
			}
		},
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hidePreloader();//隐藏加载中
			myApp.alert("网络超时，请重试");
		}
	});
}
//修改销售汇率
function ModifySalesExchangerate(){
    myApp.showPreloader(_("修改中，请稍等!"));
    var request = {};
    IDs = "";
    var inventorylistCb = $("#stock_body .check_list_box span.selected"); //checked的
    for(var i = 0; i < inventorylistCb.length; i++) {
        IDs +=  inventorylistCb[i].lang+",";
    }
    IDs = IDs.substring(0, IDs.lastIndexOf(','));
    request.OrderIds = IDs;
    request.SalesExchangerate = $("#salesExchangerate").val();
    $.ajax({
        url: "/team/updatePurchaseExchangerate", //提交地址/Team/BatchUpdateDia
        type: "POST", //提交方式
        data: JSON.stringify(request),
        contentType: "application/json; charset=utf-8",
        timeout: 30000, //超时时间：30秒
        success: function(result) {
            var _result = eval('(' + result + ')'); //eval()解析单个json对象
            if(_result.msgcode == true) {
                $(".SalesExchangerate_box").hide();
                myApp.hidePreloader();//隐藏加载中
                myApp.alert(_(_result.msginfo));
                getOrder(); //订单搜索
            } else {
                myApp.alert(_(_result.msginfo) );
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            myApp.hidePreloader();//隐藏加载中
            myApp.alert("网络超时，请重试");
        }
    });
}



//日期格式化（年-月-日）
function YearDateFormat2(dateValue) {

    if (dateValue != null && dateValue !="" && dateValue !=undefined) {

        var CurrentDate = "";

        var datetime = new Date(dateValue);

        var Year = datetime.getFullYear();
        var Month = datetime.getMonth() + 1;
        var Day = datetime.getDate();

        CurrentDate += Year + "-";

        if (Month >= 10) {
            CurrentDate += Month + "-";
        }else {
            CurrentDate += "0" + Month + "-";
        }

        if (Day >= 10) {
            CurrentDate += Day + " ";
        }else {
            CurrentDate += "0" + Day + " ";
        }

        if (CurrentDate == "01-01 00:00") {
            CurrentDate = "";
        }

        return CurrentDate;//08-09 20:39

    } else {
        return "-";
    }
}

function calMoney(){
    var chargingAmount=Number($("#_chargingAmount").val());
    if(chargingAmount>0){
        $("#remarks_inp").show();
        $("#arrivalTime_inp").show();
        $("#_remarks2").addClass("error");
        $("#_remarks2").prop("required",true);
        $("#_remarks2").val('');
    }else{
        $("#remarks_inp").hide();
        $("#arrivalTime_inp").hide();
        $("#_remarks2").removeClass("error");
        $("#_remarks2").prop("required",false);
        $("#_remarks2").val('');
    }
}